package org.lib93.com.libSkin.utils

import android.content.Context
import android.content.SharedPreferences

/**
 * 数据缓存类
 */
class  SkinPreference {
    private val SKIN_SHARED = "skins"
    private val SKIN_PATH = "skin_path"//皮肤插件地址key
    private  var sp:SharedPreferences;
    private constructor(context: Context){
        sp = context.getSharedPreferences(SKIN_SHARED, Context.MODE_PRIVATE)//初始化SharedPreferences
    }
    companion object{

        @Volatile private var instance: SkinPreference? = null
        fun getInstance(context: Context) =
            instance ?: synchronized(this) {
                instance ?: SkinPreference(context).also { instance = it }
            }
    }

    /**
     * 保存皮肤插件地址
     */
    fun setSkin(path:String){
        sp.edit().putString(SKIN_PATH,path).apply()//异步提交保存皮肤插件地址
    }

    /**
     * 清除皮肤插件地址
     */
    fun reset(){
        sp.edit().remove(SKIN_PATH).apply()
    }

    /**
     * 获取皮肤插件地址
     */
    fun getSkin() = sp.getString(SKIN_PATH,null)
}